const fs=require('fs')
const path=require('path')

let originFile=path.join(__dirname,'rmmz_core.js')
let outDirName='rmmz_core'
let outDir=path.join(__dirname,outDirName)

let fileStr=fs.readFileSync(originFile,{
    encoding:'utf-8'
})
//console.log(fileStr)
let chunks=fileStr.split('//-----------------------------------------------------------------------------')
let names=[]
chunks.splice(0,1) //去掉标题那一块
chunks.forEach(chunk=>{
    //console.log(chunk)
    let reg=/\/\/\s(\w+?)\s/
    if(reg.test(chunk)){
        let name=RegExp.$1+'.js'
        console.log(name)
        names.push(name)
        fs.writeFileSync(path.join(outDir,name),chunk)
    }
})

for(let i=0;i<names.length;i++){
    names[i]=`'js/${outDirName}/${names[i]}',\n`
}
let fileNames=names.join('')

fs.writeFileSync(path.join(outDir,'fileNames.txt'),fileNames)